import pandas as pd
from datetime import date
import os
import time
import numpy as np
import glob
import seaborn as sns
import altair as alt
import matplotlib.pyplot as plt
from plotly import graph_objs as go
import plotly.offline as pyo
import ipywidgets as w
from IPython.display import display
pyo.init_notebook_mode()
%matplotlib inline
path = os.getcwd()+"/clean/"+"inventory_all.csv"
inventory = pd.read_csv(path,infer_datetime_format=True,parse_dates=True,encoding='utf8',index_col='VIN: ')
inventory.head()
sortedInventory = inventory[inventory["priceChanged"]==True].sort_values(by=["scrapeDate"])
trace1 = {
'x': sortedInventory['scrapeDate'],
'y': sortedInventory['internetPrice'],
'type': 'box',
'name':'col 1',
'marker': {'color': 'blue'}
}
data = [trace1]
layout=dict(
title='Subarban Ford Price Changes',
xaxis=dict(
title='scrapeDate',
type='date',
tickformat='%Y-%m-%d',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
),
yaxis=dict(
title='internetPrice',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
)
)
fig = go.FigureWidget(data=data, layout=layout)
def update_fig(change):
aux_df = sortedInventory[sortedInventory['model'] == change['new']]
with fig.batch_update():
for trace, column in zip(fig.data, ['internetPrice']):
trace.x = aux_df['scrapeDate']
trace.y = aux_df[column]
def update_fig2(change):
aux_df = sortedInventory[sortedInventory['model'] == drop.value]
aux_df = aux_df[aux_df['name'] == change['new']]
with fig.batch_update():
for trace, column in zip(fig.data, ['internetPrice']):
trace.x = aux_df['scrapeDate']
trace.y = aux_df[column]
drop = w.Dropdown(options=sortedInventory['model'].unique().tolist())
drop2 = w.Dropdown(options=sortedInventory['name'].unique().tolist())
drop.observe(update_fig, names='value')
drop2.observe(update_fig2, names='value')
display(w.VBox([w.HBox([drop, drop2]), fig]))
pyo.iplot(data, filename = 'ford_boxplot')
inventorycounts= inventory.groupby(['scrapeDate','model']).count()['name'].reset_index()
trace = {
'x': inventorycounts['scrapeDate'],
'y': inventorycounts['name'],
'type': 'bar',
'name':'col 1',
'marker': {'color': 'blue'}
}
data = [trace]
layout=dict(
title='Subarban Ford Inventory Changes',
xaxis=dict(
title='scrapeDate',
type='date',
tickformat='%Y-%m-%d',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
),
yaxis=dict(
title='# Cars',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
)
)
fig = go.FigureWidget(data=data, layout=layout)
def update_fig1(change):
aux_df = inventorycounts[inventorycounts['model'] == change['new']]
with fig.batch_update():
for trace, column in zip(fig.data, ['name']):
trace.x = aux_df['scrapeDate']
trace.y = aux_df[column]
drop = w.Dropdown(options=inventorycounts['model'].unique().tolist())
drop.observe(update_fig1, names='value')
display(w.VBox([drop, fig]))
pyo.iplot(data, filename = 'ford_inventory')
trace1 = {
'x': sortedInventory['scrapeDate'],
'y': sortedInventory['internetPrice'],
'type': 'histogram2d',
'name':'col 1',
'colorscale':'YlGnBu'
}
data = [trace1]
layout=dict(
title='Subarban Ford Price Change Heatmap',
xaxis=dict(
title='scrapeDate',
type='date',
tickformat='%Y-%m-%d',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
),
yaxis=dict(
title='internetPrice',
ticklen=5,
titlefont=dict(
family='Old Standard TT, serif',
size=20,
color='black'
)
)
)
fig = go.FigureWidget(data=data, layout=layout)
def update_fig1(change):
aux_df = sortedInventory[sortedInventory['model'] == change['new']]
with fig.batch_update():
for trace, column in zip(fig.data, ['name']):
trace.x = aux_df['scrapeDate']
trace.y = aux_df[column]
drop = w.Dropdown(options=sortedInventory['model'].unique().tolist())
drop.observe(update_fig1, names='value')
display(w.VBox([drop, fig]))
pyo.iplot(data, filename = 'ford_heatmap')